#include "cimgwrapper.h"

#include "cimg/CImg.h"

/* -------------------------------------------------------------- */

void CImgWrapper::visualize_features (const std::string& file, std::vector<math::Vec2f> fpoints, std::vector<float> scales)
{
	cimg_library::CImg<unsigned char> img(file.c_str());

    const unsigned char color[] = { 255,0,0 };
	for(std::size_t i = 0; i < fpoints.size(); ++i)
	{
		img.draw_circle((int)fpoints[i][0],
							(int)fpoints[i][1],scales[i],color,1.0f,1);		
	}
	
	img.save("features.png");
}


/* -------------------------------------------------------------- */

void CImgWrapper::visualize_feature_matches (const std::string& file1, const std::string& file2, std::vector<std::pair<math::Vec2f, math::Vec2f> > matches)
{
	cimg_library::CImg<unsigned char> img1(file1.c_str());
	cimg_library::CImg<unsigned char> img2(file2.c_str());

	unsigned int dim = img1._width;	
	img1.append(img2);
    const unsigned char color[] = { 255,0,0 };
	for(std::size_t i = 0; i < matches.size(); ++i)
	{
		img1.draw_line( (unsigned int)matches[i].first[0],
						(unsigned int)matches[i].first[1],
						(unsigned int)matches[i].second[0]+dim,
						(unsigned int)matches[i].second[1],
						 color);
		img1.draw_circle((unsigned int)matches[i].first[0],
							(unsigned int)matches[i].first[1],2,color);
		img1.draw_circle((unsigned int)matches[i].second[0]+dim,
							(unsigned int)matches[i].second[1],2, color);
		
	}
	
	img1.save("featurematches.png");
}

